import { createStore, createLogger } from 'vuex'
// 导入user模块
import user from './modules/user'
import cart from './modules/cart'

// 导入自动导入插件
import createPersistedstate from 'vuex-persistedstate'
// 保存到cookie
// import * as Cookies from 'js-cookie'

export default createStore({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    user,
    cart
  },
  // 配置自动保存  默认保存到localStorage
  plugins: [
    createPersistedstate({
      // storage: window.sessionStorage, // 保存到会话存储
      key: 'rabbit-key',
      paths: ['user', 'cart']
      // storage: {
      //   getItem: (key) => Cookies.get(key),
      //   // Please see https://github.com/js-cookie/js-cookie#json, on how to handle JSON.
      //   setItem: (key, value) =>
      //     Cookies.set(key, value, { expires: 3, secure: true }),
      //   removeItem: (key) => Cookies.remove(key)
      // }
    }),
    // vue3 vuex插件
    createLogger()

  ]
})
